<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<title>C2 讲解-23航C | pansis.io</title>
<link rel="shortcut icon" href="https://github.pansis.site/favicon.ico">
<link href="https://github.pansis.site/styles/main.css" rel="stylesheet">
<link href="//at.alicdn.com/t/c/font_1678829_b85ccgkdqkr.css" rel="stylesheet">
<link href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css" rel="stylesheet">
<link rel="alternate" type="application/rss+xml" title="pansis.io » Feed" href="https://github.pansis.site/atom.xml">
        <meta name="description" content="A 奇异的位运算2024
F=A‾B‾+AB=A‾B+AB‾‾F=\overline A \overline B +AB=\overline {\overline A B+A \overline B}F=AB+AB=AB+AB​
按位异或
..." />
        <meta name="keywords" content="23航C" />
        <!-- OG -->
        <meta property="og:locale" content="zh_CN">
        <meta property="og:title" content="C2 讲解-23航C" />
        <meta property="og:type" content="article" />
        <meta property="og:description" content="A 奇异的位运算2024
F=A‾B‾+AB=A‾B+AB‾‾F=\overline A \overline B +AB=\overline {\overline A B+A \overline B}F=AB+AB=AB+AB​
按位异或
...">
        <meta property="og:url" content="https://github.pansis.site/post/C2 讲解-23航C/" />
        <meta property="og:site_name" content="pansis.io">
        <meta property="og:updated_time" content="2024-03-14">
        <meta property="og:image" content="" />
        <meta property="og:image:secure_url" content="">
        <meta property="og:image:alt" content="C2 讲解-23航C">
        <!-- Twitter (post.ejs) -->
        <meta name="twitter:card" content="summary_large_image">
        <meta name="twitter:title" content="C2 讲解-23航C">
        <meta name="twitter:description" content="A 奇异的位运算2024
F=A‾B‾+AB=A‾B+AB‾‾F=\overline A \overline B +AB=\overline {\overline A B+A \overline B}F=AB+AB=AB+AB​
按位异或
...">
        <!-- <meta name="twitter:site" content="@WBoy0609">
        <meta name="twitter:creator" content="@WBoy0609"> -->
        <meta name="twitter:image" content="">
</head>

<body>
    <div class="main animated">
        <div class="header animated fadeInDown">
    <div class="site_title_container">
        <div class="site_title">
            <a href="https://github.pansis.site">pansis.io</a>
        </div>
    </div>
    <div class="my_socials">
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
        <a href="https://github.pansis.site/atom.xml" title="rss" target="_blank"><i class="iconfont icon-rss"></i></a>
    </div>
</div>

    <div class="header_menu">
        
            
                <a href="/" class="menu">首页</a>
            
        
            
                <a href="/tag/GWAaV2nvk/" class="menu">程序设计课程</a>
            
        
            
                <a href="/tag/24hangc" class="menu">比赛</a>
            
        
            
                <a href="/tag/L7r9STb75/" class="menu">Python教程</a>
            
        
            
                <a href="/tags" class="menu">分类</a>
            
        
        <div class="gridea-search-div">
            <form id="gridea-search-form" action="https://github.pansis.site/search/">
                <input class="gridea-search-input" autocomplete="off" spellcheck="false" name="q"/>
            </form>
        </div>
    </div>

            <div class="autopagerize_page_element">
                <div class="content">
                    <div class="post_page">
                        <div class="post animated fadeInDown">
                            <div class="post_title post_detail_title">
                                <h2>
                                    C2 讲解-23航C
                                </h2>
                                <span class="article-info">
                                    2024-03-14, 813 words, 5 min read
                                </span>
                            </div>
                            <div class="post_content markdown">
                                <p class="md_block">
                                    <span class="md_line md_line_start md_line_end">
                                        <h1 id="a-奇异的位运算2024"><code>A</code> 奇异的位运算2024</h1>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>F</mi><mo>=</mo><mover accent="true"><mi>A</mi><mo stretchy="true">‾</mo></mover><mover accent="true"><mi>B</mi><mo stretchy="true">‾</mo></mover><mo>+</mo><mi>A</mi><mi>B</mi><mo>=</mo><mover accent="true"><mrow><mover accent="true"><mi>A</mi><mo stretchy="true">‾</mo></mover><mi>B</mi><mo>+</mo><mi>A</mi><mover accent="true"><mi>B</mi><mo stretchy="true">‾</mo></mover></mrow><mo stretchy="true">‾</mo></mover></mrow><annotation encoding="application/x-tex">F=\overline A \overline B +AB=\overline {\overline A B+A \overline B}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathdefault" style="margin-right:0.13889em;">F</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.9666600000000001em;vertical-align:-0.08333em;"></span><span class="mord overline"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8833300000000001em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathdefault">A</span></span><span style="top:-3.80333em;"><span class="pstrut" style="height:3em;"></span><span class="overline-line" style="border-bottom-width:0.04em;"></span></span></span></span></span></span><span class="mord overline"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8833300000000001em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span></span><span style="top:-3.80333em;"><span class="pstrut" style="height:3em;"></span><span class="overline-line" style="border-bottom-width:0.04em;"></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathdefault">A</span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.16666em;vertical-align:-0.08333em;"></span><span class="mord overline"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.0833300000000001em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord overline"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8833300000000001em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathdefault">A</span></span><span style="top:-3.80333em;"><span class="pstrut" style="height:3em;"></span><span class="overline-line" style="border-bottom-width:0.04em;"></span></span></span></span></span></span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord mathdefault">A</span><span class="mord overline"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8833300000000001em;"><span style="top:-3em;"><span class="pstrut" style="height:3em;"></span><span class="mord mathdefault" style="margin-right:0.05017em;">B</span></span><span style="top:-3.80333em;"><span class="pstrut" style="height:3em;"></span><span class="overline-line" style="border-bottom-width:0.04em;"></span></span></span></span></span></span></span></span><span style="top:-4.00333em;"><span class="pstrut" style="height:3em;"></span><span class="overline-line" style="border-bottom-width:0.04em;"></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.08333em;"><span></span></span></span></span></span></span></span></span></p>
<pre><code>按位异或
A  B  A^B
0  0   0
0  1   1
1  0   1
1  1   0
</code></pre>
<p>代码</p>
<pre><code class="language-c">#include &lt;stdio.h&gt;
int main()
{
    unsigned a, b;
    while (scanf(&quot;%u%u&quot;, &amp;a, &amp;b) != EOF)
    {
        printf(&quot;%u\n&quot;, ~(a ^ b));
    }
    return 0;
}
</code></pre>
<h1 id="b-小宇的基物实验物资"><code>B</code> 小宇的基物实验物资</h1>
<img src="http://cos.pansis.site/202403131553460.png/abc123" alt="image-20240313155313172" style="zoom:70%;" />
<p>提取某一位</p>
<pre><code class="language-c">if ((1u&amp;(b&gt;&gt;i))!=0)
</code></pre>
<p>代码</p>
<pre><code class="language-c">#include &lt;stdio.h&gt;
int main()
{
    unsigned int b;
    scanf(&quot;%u&quot;,&amp;b);
    for (int i = 0; i &lt; 32; ++i) {
        if ((1u&amp;(b&gt;&gt;i))!=0)
        {
            printf(&quot;%u &quot;,1u&lt;&lt;i);
        }
    }
}
</code></pre>
<h1 id="c-蓝与橙的简单位运算"><code>C</code> 蓝与橙的简单位运算</h1>
<pre><code class="language-c">#include&lt;stdio.h&gt;
int main()
{
    int num,n,key;
    while ((scanf(&quot;%d%d%d&quot;,&amp;num,&amp;n,&amp;key))!=EOF)
    {
        num&amp;=~(((1&lt;&lt;(4))-1)&lt;&lt;n);
    	num|=(key&lt;&lt;n);
        printf(&quot;%d\n&quot;,num);
    }
}
</code></pre>
<p>多保存一些位运算的代码模板，上机可以直接用</p>
<pre><code class="language-c">long long mian123(long long a,int n,int x)  //替换二进制特定位的值  //a为要转化的数字，n为替换的值（0或1），x为位数
{

    if (n==0)
        a &amp;= (~(1 &lt;&lt; x));   //将a的二进制第x位替换为0
    else  a|=(1&lt;&lt;x);        //将a的二进制第x位替换为1
    return a;
}

long long mian1234(long long x,int n)  //提取二进制的特定位  //x为要转化的数字，n为位数
{
    return x&amp;(1&lt;&lt;n);           //取出x的第m位，保存在a中（若为1，则a=2^m,否则a=0）
}


unsigned int mian2(unsigned int a1,int begin,int end,int n)   //替换二进制中特定连续位置，begin和end从0位开始，n为要替换的数，a1为被替换数
{
    a1&amp;=~(((1&lt;&lt;(end-begin+1))-1)&lt;&lt;begin);
    a1|=(n&lt;&lt;begin);
    return a1;
}

</code></pre>
<h1 id="d-数字独舞会"><strong><code>D</code> 数字独舞会</strong></h1>
<p>全局数组与局部数组</p>
<p><img src="http://cos.pansis.site/202403131602054.png/abc123" alt="image-20240313160221003" style="zoom:70%;" /><img src="http://cos.pansis.site/202403131602777.png/abc123" alt="image-20240313160243687" style="zoom:67%;" /></p>
<pre><code class="language-c">#include &lt;stdio.h&gt;
int s[1000005];
int main()
{
    int N, temp, cnt = 0;
    scanf(&quot;%d&quot;, &amp;N);
    for (int i = 0; i &lt; N; i++)
    {
        scanf(&quot;%d&quot;, &amp;temp);
        if (s[temp]==1)
            continue;
        else
        {
            cnt +=1;
            s[temp] = 1;
        }
    }
    printf(&quot;%d\n&quot;, cnt);
}
</code></pre>
<h1 id="e-位操作器"><code>E</code> 位操作器</h1>
<p>建议每次操作1位</p>
<pre><code class="language-c">#include&lt;stdio.h&gt;
long long zhiling(long long n,int l, int r)
{
    for (int i = l; i &lt;= r; ++i) {
        n&amp;=(~(1ll&lt;&lt;i));
    }
    return n;
}
long long zhi1(long long n,int l, int r)
{
    for (int i = l; i &lt;= r; ++i) {
        n|=((1ll&lt;&lt;i));
    }
    return n;
}
long long fanzhuan(long long n,int l, int r)
{
    for (int i = l; i &lt;= r; ++i) {
        if (((n&gt;&gt;i)&amp;1)==0)
             n|=((1ll&lt;&lt;i));
        else
            n&amp;=(~(1ll&lt;&lt;i));
    }
    return n;
}
int main()
{
    long long n;
    int op,l,r;
    scanf(&quot;%lld&quot;,&amp;n);
    while ((scanf(&quot;%d%d%d&quot;,&amp;op,&amp;l,&amp;r))!=EOF)
    {
        if (op==1)
            n= zhiling(n,l,r);
        if (op==2)
            n=zhi1(n,l,r);
        if(op==3)
            n= fanzhuan(n,l,r);
    }
    printf(&quot;%lld&quot;,n);


}
</code></pre>
<h1 id="f-字母频率"><code>F</code> 字母频率</h1>
<p>dev调试</p>
<pre><code class="language-c">#include &lt;stdio.h&gt;
int main()
{
    char a;
    scanf(&quot;%c&quot;,&amp;a);
    int num=0;int anum=0;
    char s;
    getchar();
    while ((scanf(&quot;%c&quot;,&amp;s))!=EOF)
    {
        if (s==a || s-a=='a'-'A' ||s-a=='A'-'a')
            anum++;
        if (s!=' ' &amp;&amp; s!='\n')
            num++;
    }
    printf(&quot;%d\n%.2f%%&quot;,anum,1.0*100*anum/num);
}
</code></pre>
<h1 id="g-czx-的植树节"><code>G</code> czx 的植树节</h1>
<img src="http://cos.pansis.site/202403131615227.jpg/abc123" alt="3afe69f5eab35c0d2f26979028d88e5" style="zoom:50%;" />
<pre><code>#include&lt;stdio.h&gt;

int main()
{
    int t;
    long long a,m,l,r;
    scanf(&quot;%d&quot;,&amp;t);
    while (t--)
    {
        long long num=0;
        scanf(&quot;%lld%lld%lld%lld&quot;,&amp;a,&amp;m,&amp;l,&amp;r);
        long long k1=(l-a)/m;
        long long k2=(r-a)/m;
        if (k2*m&gt;r-a)
            k2--;
        if (k1*m&lt;l-a)
            k1++;
        printf(&quot;%lld\n&quot;,k2-k1+1);
    }
}
</code></pre>
<h1 id="g">G</h1>
<br />
                                            
                                </p>
                            </div>
                            <div class="post_footer">
                                
                                    <div class="meta">
                                        <div class="info"><span class="field tags"><i class="iconfont icon-tag-sm"></i>
                                                
                                                    <a href="https://github.pansis.site/tag/24hc/" class="article-info">
                                                        23航C
                                                    </a>
                                                    
                                            </span>
                                        </div>
                                    </div>
                                    
                                        
                                            <div class="next-post" style="margin-top: 20px;">
                                                <div class="next">下一篇</div>
                                                <a href="https://github.pansis.site/post/1.1 脉动阵列/">
                                                    <h3 class="post-title">
                                                        1.1 脉动阵列
                                                    </h3>
                                                </a>
                                            </div>
                                            
                            </div>
                        </div>
                        
                            
                                <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<div id="gitalk-container" style="padding-bottom: 20px;"></div>
<script>
    var pageId = (location.pathname).substring(1, 49) // Ensure uniqueness and length less than 50
    pageId = pageId.endsWith('/') ? pageId.slice(0, -1) : pageId // 以斜杠结尾则去除
    var gitalk = new Gitalk({
        clientID: '9d5eba33618472c44a07',
        clientSecret: '065a85ed04333ceebfc4f01d7ca1674175730339',
        repo: 'fzxl2003.github.io',
        owner: 'fzxl2003',
        admin: ['fzxl2003'],
        id: pageId,
        distractionFreeMode: false  // Facebook-like distraction free mode
    })
    gitalk.render('gitalk-container')
</script>
                                    
                                        
                                                    
                    </div>
                </div>
            </div>
    </div>
    <div class="footer">
    
    <div class="powered_by">
        <a href="https://codeberg.org/kytrun/gridea-theme-one" target="_blank">Theme One,</a>
        <a href="https://open.gridea.dev/" target="_blank">Powered by Gridea&#65281;</a>
    </div>
    
    
        <div class="footer_slogan">
            Powered by <a href="https://github.com/getgridea/gridea" target="_blank">Gridea</a>
        </div>
    
    <div id="back_to_top" class="back_to_top">
        <span>△</span>
    </div>
    
</div>

<script src="https://github.pansis.site/media/scripts/util.js"></script>
        <link rel="stylesheet" href="//unpkg.com/@highlightjs/cdn-assets@11.5.1/styles/default.min.css">
        <script src="//unpkg.com/@highlightjs/cdn-assets@11.5.1/highlight.min.js"></script>
        <script>hljs.highlightAll();</script>
</body>

</html>